#include "xc_private.h"
int xc_domain_create(int xc_handle,
- unsigned int mem_kb,
- int cpu,
- float cpu_weight,
u32 *pdomid)
{
- int err, errno_saved;
+ int err;
dom0_op_t op;
- u32 vcpu = 0; /* FIXME, hard coded initial pin to vcpu 0 */
- cpumap_t cpumap = 1 << cpu;
op.cmd = DOM0_CREATEDOMAIN;
op.u.createdomain.domain = (domid_t)*pdomid;
return err;
*pdomid = (u16)op.u.createdomain.domain;
-
- if ( (cpu != -1) &&
- ((err = xc_domain_pincpu(xc_handle, *pdomid, vcpu, &cpumap)) != 0) )
- goto fail;
-
- if ( (err = xc_domain_setcpuweight(xc_handle, *pdomid, cpu_weight)) != 0 )
- goto fail;
-
- if ( (err = xc_domain_setmaxmem(xc_handle, *pdomid, mem_kb)) != 0 )
- goto fail;
-
- if ( (err = do_dom_mem_op(xc_handle, MEMOP_increase_reservation,
- NULL, mem_kb/4, 0, *pdomid)) != (mem_kb/4) )
- {
- if ( err > 0 )
- errno = ENOMEM;
- err = -1;
- goto fail;
- }
-
return 0;
-
- fail:
- errno_saved = errno;
- (void)xc_domain_destroy(xc_handle, *pdomid);
- errno = errno_saved;
- return err;
}
op.u.setdomainmaxmem.max_memkb = max_memkb;
return do_dom0_op(xc_handle, &op);
}
+
+int xc_domain_memory_increase_reservation(int xc_handle,
+ u32 domid,
+ unsigned int mem_kb)
+{
+ int err;
+
+ err = do_dom_mem_op(xc_handle, MEMOP_increase_reservation, NULL,
+ mem_kb / 4, 0, domid);
+ if (err == mem_kb / 4)
+ return 0;
+
+ if (err > 0) {
+ errno = ENOMEM;
+ err = -1;
+ }
+ return err;
+}
}
/* Create domain on CPU -1 so that it may auto load-balance in future. */
- if ( xc_domain_create(xc_handle, nr_pfns * (PAGE_SIZE / 1024),
- -1, 1, &dom) )
+ if ( xc_domain_create(xc_handle, &dom) )
{
- xcio_error(ioctxt, "Could not create domain. pfns=%ld, %ldKB",
- nr_pfns, nr_pfns * (PAGE_SIZE / 1024));
+ xcio_error(ioctxt, "Could not create domain.");
goto out;
}
-
+ if ( xc_domain_setcpuweight(xc_handle, dom, 1) )
+ {
+ xcio_error(ioctxt, "Could not set domain cpuweight.");
+ goto out;
+ }
+ if ( xc_domain_setmaxmem(xc_handle, dom, nr_pfns * (PAGE_SIZE / 1024)) )
+ {
+ xcio_error(ioctxt, "Could not set domain maxmem. pfns=%ld, %ldKB",
+ nr_pfns, nr_pfns * (PAGE_SIZE / 1024));
+ goto out;
+ }
+ if ( xc_domain_memory_increase_reservation(xc_handle, dom,
+ nr_pfns * (PAGE_SIZE / 1024)) )
+ {
+ xcio_error(ioctxt,
+ "Could not increase domain memory reservation. pfns=%ld",
+ nr_pfns);
+ goto out;
+ }
+
ioctxt->domain = dom;
xcio_info(ioctxt, "Created domain %u\n", dom);
{
XcObject *xc = (XcObject *)self;
- unsigned int mem_kb = 0;
- int cpu = -1;
- float cpu_weight = 1;
u32 dom = 0;
int ret;
- static char *kwd_list[] = { "dom", "mem_kb", "cpu", "cpu_weight", NULL };
+ static char *kwd_list[] = { "dom", NULL };
- if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iiif", kwd_list,
- &dom, &mem_kb, &cpu, &cpu_weight))
+ if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|i", kwd_list, &dom))
return NULL;
- if ( (ret = xc_domain_create(
- xc->xc_handle, mem_kb, cpu, cpu_weight, &dom)) < 0 )
+ if ( (ret = xc_domain_create(xc->xc_handle, &dom)) < 0 )
return PyErr_SetFromErrno(xc_error);
return PyInt_FromLong(dom);
return zero;
}
+static PyObject *pyxc_domain_setcpuweight(PyObject *self,
+ PyObject *args,
+ PyObject *kwds)
+{
+ XcObject *xc = (XcObject *)self;
+
+ u32 dom;
+ float cpuweight = 1;
+
+ static char *kwd_list[] = { "dom", "cpuweight", NULL };
+
+ if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|f", kwd_list,
+ &dom, &cpuweight) )
+ return NULL;
+
+ if ( xc_domain_setcpuweight(xc->xc_handle, dom, cpuweight) != 0 )
+ return PyErr_SetFromErrno(xc_error);
+
+ Py_INCREF(zero);
+ return zero;
+}
+
static PyObject *pyxc_domain_getinfo(PyObject *self,
PyObject *args,
PyObject *kwds)
return zero;
}
+static PyObject *pyxc_domain_memory_increase_reservation(PyObject *self,
+ PyObject *args,
+ PyObject *kwds)
+{
+ XcObject *xc = (XcObject *)self;
+
+ u32 dom;
+ unsigned long mem_kb;
+
+ static char *kwd_list[] = { "dom", "mem_kb", NULL };
+
+ if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list,
+ &dom, &mem_kb) )
+ return NULL;
+
+ if ( xc_domain_memory_increase_reservation(xc->xc_handle, dom, mem_kb) )
+ return PyErr_SetFromErrno(xc_error);
+
+ Py_INCREF(zero);
+ return zero;
+}
+
static PyMethodDef pyxc_methods[] = {
{ "domain_create",
METH_VARARGS | METH_KEYWORDS, "\n"
"Create a new domain.\n"
" dom [int, 0]: Domain identifier to use (allocated if zero).\n"
- " mem_kb [int, 0]: Memory allocation, in kilobytes.\n"
"Returns: [int] new domain identifier; -1 on error.\n" },
{ "domain_dumpcore",
" cpumap [int, -1]: Bitmap of usable CPUs.\n\n"
"Returns: [int] 0 on success; -1 on error.\n" },
+ { "domain_setcpuweight",
+ (PyCFunction)pyxc_domain_setcpuweight,
+ METH_VARARGS | METH_KEYWORDS, "\n"
+ "Set cpuweight scheduler parameter for domain.\n"
+ " dom [int]: Identifier of domain to be changed.\n"
+ " cpuweight [float, 1]: VCPU being pinned.\n"
+ "Returns: [int] 0 on success; -1 on error.\n" },
+
{ "domain_getinfo",
(PyCFunction)pyxc_domain_getinfo,
METH_VARARGS | METH_KEYWORDS, "\n"
" state_file [str]: Name of state file. Must not currently exist.\n"
" progress [int, 1]: Bool - display a running progress indication?\n\n"
"Returns: [int] 0 on success; -1 on error.\n" },
- { "plan9_build",
- (PyCFunction)pyxc_plan9_build,
- METH_VARARGS | METH_KEYWORDS, "\n"
- "Build a new Plan 9 guest OS.\n"
- " dom [long]: Identifier of domain to build into.\n"
- " image [str]: Name of kernel image file. May be gzipped.\n"
- " cmdline [str, n/a]: Kernel parameters, if any.\n\n"
- "Returns: [int] 0 on success; -1 on error.\n" },
{ "linux_restore",
(PyCFunction)pyxc_linux_restore,
" vcpus [int, 1]: Number of Virtual CPUS in domain.\n\n"
"Returns: [int] 0 on success; -1 on error.\n" },
+ { "plan9_build",
+ (PyCFunction)pyxc_plan9_build,
+ METH_VARARGS | METH_KEYWORDS, "\n"
+ "Build a new Plan 9 guest OS.\n"
+ " dom [long]: Identifier of domain to build into.\n"
+ " image [str]: Name of kernel image file. May be gzipped.\n"
+ " cmdline [str, n/a]: Kernel parameters, if any.\n\n"
+ "Returns: [int] 0 on success; -1 on error.\n" },
+
{ "vmx_build",
(PyCFunction)pyxc_vmx_build,
METH_VARARGS | METH_KEYWORDS, "\n"
" maxmem_kb [long]: .\n"
"Returns: [int] 0 on success; -1 on error.\n" },
+ { "domain_memory_increase_reservation",
+ (PyCFunction)pyxc_domain_memory_increase_reservation,
+ METH_VARARGS | METH_KEYWORDS, "\n"
+ "Increase a domain's memory reservation\n"
+ " dom [int]: Identifier of domain.\n"
+ " mem_kb [long]: .\n"
+ "Returns: [int] 0 on success; -1 on error.\n" },
+
{ NULL, NULL, 0, NULL }
};